class Solution(object):
    def relativeSortArray(self, arr1, arr2):
        return sorted(arr1, key=lambda x: (0, arr2.index(x)) if x in arr2 else (1, x))